<!doctype html>
<html>
<head>
<?php $this->load->view('admin/common_head'); ?>
</head>
<body>
<div class="wrap">
	<div class="nav">
		<?php $tabs = array('member'=>'', 'broker'=>'', 'system'=>'', 'default'=>''); $tabs[$type] = 'class="current"'; ?>
		<ul class="cc">
			<li <?php echo $tabs['member'];?>><a href="<?php echo site_url('admin/user_group/index?type=member'); ?>">会员组权限</a></li>
			<li <?php echo $tabs['broker'];?>><a href="<?php echo site_url('admin/user_group/index?type=broker'); ?>">经纪人组权限</a></li>
			<li <?php echo $tabs['system'];?>><a href="<?php echo site_url('admin/user_group/index?type=system'); ?>">管理组权限</a></li>
			<li <?php echo $tabs['default'];?>><a href="<?php echo site_url('admin/user_group/index?type=default'); ?>">默认组权限</a></li>
		</ul>
	</div>
	<form class="J_ajaxForm" action="<?php echo site_url('admin/user_group/saves'); ?>" method="post">
		<input type="hidden" name="type" value="<?php echo $type; ?>" />
		<div class="table_list">
			<table width="100%" id="J_group_table">
				<col width="50" />
				<col width="150" />
				<thead>
					<tr>
						<td>编号</td>
						<td>用户组名称</td>
						<td>操作</td>
					</tr>
				</thead>
			<?php if($groups) {?>
				<tbody id="J_groupList">
				<?php
					foreach($groups as $group) {
						if($group['type'] ==$type) {
				?>
					<tr>
						<td><?php echo $group['groupid']; ?></td>
						<td><input type="text" class="input length_2" name="name[<?php echo $group['groupid'];?>]" value="<?php echo $group['name'];?>" /></td>
						<td><a href="<?php echo site_url('admin/user_group/right?groupid='.$group['groupid']);?>" class="mr10">[编辑]</a> <?php if($group['groupid'] > 7) { ?><a href="<?php echo site_url('admin/user_group/del?groupid='.$group['groupid']);?>" class="J_ajax_del">[删除]</a><?php } ?></td>
					</tr>
				<?php 
						}
					}
				?>
				</tbody>
			<?php } ?>
			<?php if($type != 'default') { ?>
				<tbody id="J_groups_add_temp">
					<tr>
						<td></td>
						<td><input id="J_new_group_name" type="text" class="input length_2" name="new_name[]" /></td>
						<td><a id="J_inset_new_group" href="" class="link_add">添加</a></td>
					</tr>
				</tbody>
			<?php } ?>
			</table>
		</div>
		<div class="btn_wrap">
			<div class="btn_wrap_pd" id="J_sub_wrap">
				<button type="submit" class="btn btn_submit">提交</button>
			</div>
		</div>
	</form>
</div>
<?php $this->load->view('admin/common_footer'); ?>
<script>
Wind.use('draggable', function(){
	var group_list = $('#J_groupList');
	
	//添加新组
	$('#J_inset_new_group').click(function(e){
		e.preventDefault();
		var new_group_name = $('#J_new_group_name');

		if (!(new_group_name.val().replace(/\s/g, ''))) {
			new_group_name.focus();
			return false;
		}
		new_group_html = '<tr class="ct">\
			<td></td>\
			<td><input type="text" value="'+ new_group_name.val() +'" name="new_name[]" class="input length_2"></td>\
			<td>\
				<a class="mr10 J_new_group_del" href="">[删除]</a>\
			</td>\
		</tr>';
		group_list.append(new_group_html);
		new_group_name.val('');
	});
	
	//删除未提交的组
	Wind.use('dialog',function() {
		group_list.on('click', 'a.J_new_group_del', function(e) {
			e.preventDefault();
			var $this = $(this);
			Wind.dialog.confirm('确定要删除吗？',function() {
				$this.parents('tr.ct').fadeOut('fast', function(){
					$(this).remove();
				});
			})
		});
	});
})
</script>
</body>
</html>